package org.infocorp.controller;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.infocorp.domain.Person;
import org.infocorp.service.PersonService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * REST service provider
 * 
 * Only GET and POST will return values
 * PUT and DELETE will not.
 */
@Controller
public class RestProviderController {

	protected static Logger logger = Logger.getLogger("controller");
	
	@Resource(name="personService")
	private PersonService personService;
	       	
    @RequestMapping(value = "/person/{id}", 
    							method = RequestMethod.GET, 
    							headers="Accept=application/xml, application/json")
	public @ResponseBody Person getPerson(@PathVariable("id") String dni) {
    	logger.debug("Provider has received request to get person with id: " + dni);
    	
    	// Call service here
		return personService.get(dni);
    }
    // el GET es para consultar                 
    
}
